﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
#if UNITY_EDITOR
using UnityEditor;
#endif

[Serializable]
public class GT_NodeBase : ScriptableObject {
    #region Variables
    public bool isSelected = false;
    public string nodeName;
    public Rect nodeRect;
    public GT_NodeGraph parentGraph;
    public NodeType nodeType;
    protected GUISkin nodeSkin;
    #endregion



    #region Subclasses
    [Serializable]
    public class GT_NodeInput
    {
        public bool isOccupied = false;
        public GT_NodeBase inputNode;
    }

    [Serializable]
    public class GT_NodeOutput
    {
        public bool isOccupied = false;
    }
    #endregion

    #region Main Methods
    public virtual void InitNode() { } 

    public virtual void UpdateNode(Event e, Rect viewRect)
    {
        ProcessEvents(e, viewRect);
    }

    #if UNITY_EDITOR
    public virtual void UpdateNodeGUI(Event e, Rect viewRect, GUISkin viewSkin)
    {
        ProcessEvents(e, viewRect);

        if (!isSelected)
        {
            GUI.Box(nodeRect, nodeName, viewSkin.GetStyle("NodeDefault"));
        } else
        {
            GUI.Box(nodeRect, nodeName, viewSkin.GetStyle("NodeSelected"));
        }

        EditorUtility.SetDirty(this);
    }

    public virtual void DrawNodeProperties()
    {

    }
    #endif
    #endregion

    #region Utility Methods
    void ProcessEvents(Event e, Rect viewRect)
    {
        if (isSelected)
        {
            if (e.type == EventType.MouseDrag)
            {
                if (viewRect.Contains(e.mousePosition))
                {
                    nodeRect.x += e.delta.x;
                    nodeRect.y += e.delta.y;
                }
            }
        }
        
    } 
    #endregion
}